package gov.kqqzyyy.monkey.orderpad.broadcastreceiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;

import com.socks.library.KLog;

import gov.kqqzyyy.monkey.orderpad.ui.NavigationBaseActivity;


public class WifiStatusReveiver extends BroadcastReceiver {

    private final Context mContext;

    public WifiStatusReveiver(Context context) {
        this.mContext = context;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) { //wifi链接状态改变
            WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
            WifiInfo wifiInfo = wifiManager.getConnectionInfo();
            if (wifiInfo != null) {
                String ssid = wifiInfo.getSSID().replace("\"", "");
                if (!ssid.contains("<unknown ssid>")) {
//                    KLog.d("APE", ssid);
                    ((NavigationBaseActivity) mContext).setWIFIInfo(ssid);
                    int currentWifi = ssid.contains("jsc") ? 1 : 2;
                    ((NavigationBaseActivity) mContext).setCurrentWifi(currentWifi);
                }
            } else {
                ((NavigationBaseActivity) mContext).setWIFIInfo("未连接");
                ((NavigationBaseActivity) mContext).setCurrentWifi(0);
            }
        }
    }

}
